/**
 * 
 */
package com.business.img.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.img.entity.ImgType;
import com.business.img.service.ImgTypeService;
import com.github.pagehelper.PageInfo;
import com.phiz.common.base.BaseController;
import com.phiz.common.base.Result;
import com.phiz.common.exception.HzBaseException;

/**
 * <p>
 * 
 * @ClassName: ImgTypeController
 *             </p>
 *             <p>
 * @Description: TODO(这里用一句话描述这个类的作用)
 *               </p>
 *               <p>
 * @author 淳峰
 *         </p>
 *         <p>
 * @date 2018年11月15日 下午8:58:18
 *       </p>
 *       <p>
 *       </p>
 */
@RequestMapping("/img/type")
@Controller
public class ImgTypeController extends BaseController {

	@Autowired
	private ImgTypeService imgTypeService;

	@RequestMapping("page")
	@ResponseBody
	public Result list(ImgType type, Integer pageSize, Integer pageNum) {
		PageInfo<ImgType> page = imgTypeService.findPage(pageSize, pageNum, type);
		return SUCCESS(page);
	}

	@RequestMapping("/detail")
	@ResponseBody
	public Result toEdit(Long id) {
		ImgType type = imgTypeService.selectByPrimaryKey(id);
		return SUCCESS(type);
	}

	@RequestMapping("/save")
	@ResponseBody
	public Result save(ImgType type) {
		try {
			imgTypeService.insertSelective(type);
		} catch (HzBaseException e) {
			return ERROR(e);
		}
		return SUCCESS();
	}

	@RequestMapping("/edit")
	@ResponseBody
	public Result edit(ImgType type) {
		try {
			imgTypeService.updateByPrimaryKeySelective(type);
		} catch (HzBaseException e) {
			return ERROR(e);
		}
		return SUCCESS();
	}

	@RequestMapping("/del")
	@ResponseBody
	public Result del(@RequestParam(value = "id[]") Long[] id) {
		try {
			for (Long temp : id) {
				imgTypeService.deleteByPrimaryKey(temp);
			}
		} catch (Exception e) {
			return ERROR();
		}
		return SUCCESS();
	}

}
